package com.yaofeng.mybatis.modules.sys.service.impl;

import com.yaofeng.mybatis.modules.sys.entity.Menu;
import com.yaofeng.mybatis.modules.sys.mapper.MenuMapper;
import com.yaofeng.mybatis.modules.sys.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yaofeng.mybatis.modules.sys.vo.SelectTreeVo;
import com.yaofeng.mybatis.util.SelectTreeBuildUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.security.PrivateKey;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 菜单权限表 服务实现类
 * </p>
 *
 * @author yaofeng
 * @since 2019-11-12
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Resource
    private  MenuMapper menuMapper;

    @Override
    public List<SelectTreeVo> buildSelectTreeNode() {
        List<SelectTreeVo>  selectTreeVoList =  menuMapper.findMenuTreeList();
        if (!CollectionUtils.isEmpty(selectTreeVoList)) {
            SelectTreeBuildUtil treeBuildUtil = new SelectTreeBuildUtil(selectTreeVoList);
            selectTreeVoList = treeBuildUtil.builTree();
        }
        return selectTreeVoList;
    }

    @Override
    public List<SelectTreeVo> findMenuList(Map<String, Object> params) {
        List<SelectTreeVo>  voList =  menuMapper.findMenuList(params);
        if (!CollectionUtils.isEmpty(voList)) {
            SelectTreeBuildUtil treeBuildUtil = new SelectTreeBuildUtil(voList);
            voList = treeBuildUtil.builTree();
        }
        return voList;
    }

    @Override
    public List<String> getBtnPermsByUserId(Long userId) {
        return menuMapper.getBtnPermsByUserId(userId);
    }
}
